<template>
  <a-card :bordered="false">
    <!--金额统计区域-->
    <a-row>
      <a-col :span="8">
        <a-statistic title="用户钱包余额总计(元)" :precision="2" :value="sumData.balanceTotal" />
      </a-col>
      <a-col :span="8">
        <a-statistic title="用户余额消费总计(元)" :precision="2" :value="sumData.usedTotal" />
      </a-col>
    </a-row>
    <div style="margin-top: 20px;">
    </div>
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="昵称">
              <j-input placeholder="请输入昵称" v-model="queryParam.nickname"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="用户手机号">
              <j-input placeholder="请输入用户手机号" v-model="queryParam.phone"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
    </div>

    <!-- table区域-begin -->
    <div>

      <a-table ref="table" size="middle" :scroll="{x:true}" bordered rowKey="id" :columns="columns" :dataSource="dataSource" :pagination="ipagination"
        :loading="loading" class="j-table-force-nowrap" @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="55px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;" />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="showDetails(record)">消费明细</a>
        </span>

      </a-table>
    </div>

    <ums-balance-log-modal ref="modalForm" @ok="modalFormOk"></ums-balance-log-modal>
  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import JInput from '@/components/jeecg/JInput'
import { getAction } from "@api/manage"
import UmsBalanceLogModal from './modules/UmsBalanceLogModal'

export default {
  name: 'UmsBalanceLogList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    JInput,
    UmsBalanceLogModal
  },
  data () {
    return {
      description: 'ums_balance_log管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '用户昵称',
          align: "center",
          dataIndex: 'nickname'
        },
        {
          title: '手机号',
          align: "center",
          dataIndex: 'phone'
        },
        {
          title: '钱包余额',
          align: "center",
          dataIndex: 'balance',
          sorter: true,
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: "/member/umsBalanceLog/walletList",
        delete: "/member/umsBalanceLog/delete",
        query: "/member/umsBalanceLog/sum",
        deleteBatch: "/member/umsBalanceLog/deleteBatch",
        exportXlsUrl: "/member/umsBalanceLog/exportXls",
        importExcelUrl: "member/umsBalanceLog/importExcel",
      },
      sumData: {
        balanceTotal: 0,
        usedTotal: 0,
      },
      dictOptions: {},
    }
  },
  created () {
    this.querySum()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    initDictConfig () {
    },
    querySum () {
      getAction(this.url.query).then(res => {
        if (res.code === 200) {
          this.sumData = res.result
        } else {
          this.$message.error(res.message)
        }
      })
    },
    showDetails (record) {
      this.$refs.modalForm.show(record)
      this.$refs.modalForm.title = "消费明细"
      this.$refs.modalForm.disableSubmit = false
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>